<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>吃啥</title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <!-- <link rel="shortcut icon" href="/favicon.ico"> -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="stylesheet" href="../public/css/reset.css">
  <link rel="stylesheet" href="../public/css/iconfont.css">

  <link rel="stylesheet" href="http://g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
  <link rel="stylesheet" href="http://g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
  <link rel="stylesheet" href="http://g.alicdn.com/msui/sm/0.6.2/css/??sm.min.css,sm-extend.min.css">
</head>

<body>
  <div class="page">
    <header class="bar bar-nav">
      <a class="button button-link button-nav pull-left" href="javascript:history.back(-1)" data-transition='slide-out'>
        <span class="icon icon-left"></span>
        返回
      </a>
      <h1 class="title">美食营养测评</h1>
    </header>
    <div class="content">
      <div class="list-block">
        <ul>
          <!-- Text inputs -->
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-gender"></i></div>
              <div class="item-inner">
                <div class="item-title label">营养指标</div>
                <div class="item-input">
                  <select id="auditorStandard">
                    <option value="优秀">优秀</option>
                    <option value="一般般">一般般</option>
                  </select>
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-name"></i></div>
              <div class="item-inner">
                <div class="item-title label">消化率</div>
                <div class="item-input">
                  <input id="digestionAvailability" type="number" placeholder="0%">
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-email"></i></div>
              <div class="item-inner">
                <div class="item-title label">热能和营养素的量</div>
                <div class="item-input">
                  <input id="nutritionData" type="number" placeholder="0%">
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-password"></i></div>
              <div class="item-inner">
                <div class="item-title label">利用率</div>
                <div class="item-input">
                  <input id="userAvailability" type="number" placeholder="0%" class="">
                </div>
              </div>
            </div>
          </li>

          <!-- Date -->
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-calendar"></i></div>
              <div class="item-inner">
                <div class="item-title label">色、香、味、型</div>
                <div class="item-input">
                  <input id="userFeel" type="text" placeholder="空空如也">
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-calendar"></i></div>
              <div class="item-inner">
                <div class="item-title label">营养指数</div>
                <div class="item-input">
                  <input id="nutritionDegree" type="text" placeholder="空空如也">
                </div>
              </div>
            </div>
          </li>
          <li class="align-top">
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-comment"></i></div>
              <div class="item-inner">
                <div class="item-title label">总结</div>
                <div class="item-input">
                  <textarea id="comment"></textarea>
                </div>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="content-block">
        <div class="row">
          <div class="col-50"><a href="javascript:history.back(-1)"
              class="button button-big button-fill button-danger">取消</a></div>
          <div class="col-50"><a onclick="submit()" class="button button-big button-fill button-success">提交</a></div>
        </div>
      </div>
    </div>
  </div>
  <script type='text/javascript' src='http://g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
  <script type='text/javascript' src='http://g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
  <script type='text/javascript' src='http://g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
  <script type='text/javascript' src='http://g.alicdn.com/msui/sm/0.6.2/js/??sm.min.js,sm-extend.min.js'
    charset='utf-8'></script>
  <script>
    // 加载提示框
    $(document).on('click', '.open-preloader', function () {
      $.showPreloader();
      setTimeout(function () {
        $.hidePreloader();
      }, 2000);
    });
    $(document).on('click', '.open-preloader-title', function () {
      $.showPreloader('Custom Title')
      setTimeout(function () {
        $.hidePreloader();
      }, 2000);
    });

    function submit() {
      $.showPreloader('正在提交评测')
      setTimeout(function () {
        $.hidePreloader();
      }, 2000);
      var url = window.location.toString();
      var postId = url.split('addexam/')[1]
      postId = postId.split('/')[0]
      console.log(postId)
      const auditorStandard = document.getElementById("auditorStandard").value;
      const digestionAvailability = document.getElementById("digestionAvailability").value;
      const nutritionData = document.getElementById("nutritionData").value;
      const userAvailability = document.getElementById("userAvailability").value;
      const userFeel = document.getElementById("userFeel").value;
      const nutritionDegree = document.getElementById("nutritionDegree").value;
      const comment = document.getElementById("comment").value;
      $.ajax({
        type: 'POST',
        url: '/addexam/upExam',
        // data to be added to query string:
        data: {
          postId: postId,
          auditorStandard: auditorStandard,
          digestionAvailability: digestionAvailability,
          nutritionData: nutritionData,
          userAvailability: userAvailability,
          userFeel: userFeel,
          nutritionDegree: nutritionDegree,
          comment: comment
        },
        // type of data we are expecting in return:
        dataType: 'json',
        success: function (data) {
          console.log(data)
          if (data.err == 0) {
            window.location.href = "javascript:history.back(-1)"
          } else {
            $.alert(data.msg);
          }
        }
      })
    }
  </script>
</body>

</html>